******************************************************************
*Input: FinTech/bank borrowers dataset
*Output: Stata graph with share of firms per industry
******************************************************************
clear all 

/* use saved workspace*/
use "$output\ifp_scrapped_aggregated_industries_modified.dta", clear

gen label = "Manufacturing" if industry == "C" 
replace label = "Construction and real estate" if industry == "FL"
replace label = "Wholesale and retail trade" if industry == "G"
replace label = "Transportation and storage" if industry == "H"
replace label = "Accomodation and food service activities" if industry == "I"
replace label = "Information and communication" if industry == "J"
replace label = "Professional, scientific and technical activities" if industry == "M"
replace label = "Administrative and support service activities" if industry == "N"
replace label = "Public sector" if industry == "public"

drop if label == ""

gen bank = p2p == 0
gen ifp = p2p == 1

keep label bank ifp industry

collapse (sum) ifp bank,by(industry)

sort industry
egen tot_ifp = total(ifp)
egen tot_bank = total(bank)

replace ifp = ifp/tot_ifp*100
replace bank = bank/tot_bank*100

label var ifp "Fintech borrowers"
label var bank "Bank borrowers"

egen industry_num = group(industry)
graph hbar ifp bank , over(industry_num, gap(*1)  ///
relabel(1 "Manufacturing"  ///
2 "Construction & real estate" ///
3 "Wholesale & retail trade" ///
4 "Transportation & storage" ///
5 "Accomodation & food" ///
6 "Information & communication" ///
7 "Scientific & technical activities" ///
8 "Support services" ///
9 "Public sector" ///
) ) ///
graphregion(color(white)) blabel(bar, format(%8.1f) ) nolabel ///
 bar(1, bcolor(emerald)) bar(2, bcolor(gs10%40)  lcolor(black))  ///
legend( region(lcolor(white) ) label(1 "Fintech borrowers") label(2 "Bank borrowers") cols(2) size(medium) ) ylabel(,nogrid labsize(medium))
graph export "$figures\industries.pdf", as(pdf) replace 
graph save "$figures\industries.gph", replace 
